package com.changwen.currentactivity.activity;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ActivityUtils;
import com.changwen.currentactivity.FloatUtils;
import com.changwen.currentactivity.R;
import com.changwen.currentactivity.accessibility.AcbUtils;
import com.changwen.currentactivity.base.ClickAction;
import com.lzf.easyfloat.interfaces.OnPermissionResult;
import com.lzf.easyfloat.permission.PermissionUtils;

public class MainActivity extends AppCompatActivity implements ClickAction {

    public static void start() {
        Bundle bundle = new Bundle();
        ActivityUtils.startActivity(bundle, MainActivity.class);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setOnClickListener(R.id.btn_access_service);
    }

    @Override
    protected void onResume() {
        super.onResume();
        showFloatPermission();
    }

    private void showFloatPermission() {
        if (!PermissionUtils.checkPermission(this)) {
            PermissionUtils.requestPermission(this, new OnPermissionResult() {
                @Override
                public void permissionResult(boolean b) {
                    if (b) {
                        FloatUtils.showFloat(MainActivity.this, FloatUtils.floatTag, "", "");
                    }
                }
            });
        }
    }

    @Override
    public void onClick(View view) {
        ClickAction.super.onClick(view);
        int id = view.getId();
        if (id == R.id.btn_access_service) {
            AcbUtils.launchAccessibilitySettings(this);
        }
    }
}